extends BaseHoldItem


@onready var laser_beam: LaserBeam = $LaserBeam
var inited: bool = false
@onready var muzzle_in_shape_tester: Area2D = $MuzzleInShapeTester
var laser_music_player: AudioStreamPlayer = null


func shoot():
	if muzzle_in_shape_tester.get_overlapping_bodies().size() > 0:
		return
	
	if not inited:
		inited = true
		
		var config = item_data.item_config as ItemBaseConfig
		var player = holder as Player
		
		laser_beam.attack = config.attack + player.player_data.get_attack()
		laser_beam.sender = player
		laser_beam.critical_rate = config.critical_rate
		laser_beam.critical_bonus = config.critical_bonus
		laser_beam.knockback = config.knockback
		if config.attack_cam_shake:
			laser_beam.hit_cam_shake_strength = config.attack_cam_shake_intensity
			laser_beam.hit_cam_shake_duration = config.attack_cam_shake_duration
		
		laser_beam.set_is_enemy(false)
		
	laser_beam.set_is_casting(true)
	#laser_music_player = AudioManager.play_music("sfx_laser_shooting_loop", 0.3)
	
	
func _physics_process(delta: float) -> void:
	if Input.is_action_just_released("use"):
		laser_beam.set_is_casting(false)
		
		#if laser_music_player:
			#var tween = create_tween()
			#tween.tween_property(laser_music_player, "volume_db", -40, 0.3)
			#tween.tween_callback(Callable(laser_music_player, "stop"))
